package com.sojson.config.exception.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sojson.base.impl.Base;
import com.sojson.config.exception.TransErrorCode;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 返回状态信息类
 * 
 * @author liu
 * @date 2020-11-02
 */
@ApiModel("状态信息")
public class Status extends Base {

    /***/
    private static final long serialVersionUID = 1;

    @ApiModelProperty(value = "状态码", position = 0)
    private int code;
    @ApiModelProperty(value = "状态信息", position = 1)
    private String msg;
    @JsonIgnore
    @JSONField(serialize = false)
    @ApiModelProperty("业务状态码")
    private String subCode;
    @JsonIgnore
    @JSONField(serialize = false)
    @ApiModelProperty("业务状态描述")
    private String subMsg;
    @JsonIgnore
    @JSONField(serialize = false)
    @ApiModelProperty("如果失败,是否需要处理")
    private Boolean isDispose;

    public Status() {

    }

    public Status(int code) {
        setCode(code);
    }

    public Status(String msg) {
        setMsg(msg);
    }

    public Status(TransErrorCode transErrorCode) {
        this(transErrorCode.getCode(), transErrorCode.getMsg());
    }

    public Status(int code, String msg) {
        setCode(code);
        setMsg(msg);
    }

    public Status(int code, String msg, Boolean isDispose) {
        setCode(code);
        setMsg(msg);
        setIsDispose(isDispose);
    }

    public Status(int code, String msg, String subCode, String subMsg, Boolean isDispose) {
        setCode(code);
        setMsg(msg);
        setSubCode(subCode);
        setSubMsg(subMsg);
        setIsDispose(isDispose);
    }

    /** 获取状态码 */
    public int getCode() {
        return code;
    }

    /** 设置状态码 */
    public void setCode(int code) {
        this.code = code;
    }

    /** 获取状态信息 */
    public String getMsg() {
        return msg;
    }

    /** 设置状态信息 */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    /** 获取如果失败,是否需要处理 */
    public Boolean getIsDispose() {
        return isDispose;
    }

    /** 设置如果失败,是否需要处理 */
    public void setIsDispose(Boolean isDispose) {
        this.isDispose = isDispose;
    }

    /** 获取业务状态码 */
    public String getSubCode() {
        return subCode;
    }

    /** 设置业务状态码 */
    public void setSubCode(String subCode) {
        this.subCode = subCode;
    }

    /** 获取业务状态描述 */
    public String getSubMsg() {
        return subMsg;
    }

    /** 设置业务状态描述 */
    public void setSubMsg(String subMsg) {
        this.subMsg = subMsg;
    }

    /** 是否成功 */
    @JsonIgnore
    @JSONField(serialize = false)
    public boolean isSuccess() {
        return code == TransErrorCode.SUCCESS.getCode();
    }

    /** 是否失败 */
    @JsonIgnore
    @JSONField(serialize = false)
    public boolean isFail() {
        return code == TransErrorCode.FAIL.getCode();
    }

    /** 是否处理中 */
    @JsonIgnore
    @JSONField(serialize = false)
    public boolean isIng() {
        return code == TransErrorCode.ING.getCode();
    }

    /** 设置状态信息 */
    public void setTransErrorCode(TransErrorCode transErrorCode) {
        setCode(transErrorCode.getCode());
        setMsg(transErrorCode.getMsg());
    }

}